package com.smarthealthring.mm.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.jakewharton.rxbinding2.view.RxView;
import com.smarthealthring.mm.R;
import com.smarthealthring.mm.base.BaseActivity;
import com.smarthealthring.mm.bean.HrDetailRes;
import com.smarthealthring.mm.bean.SleepDetailRes;
import com.smarthealthring.mm.contract.HrDetailContract;
import com.smarthealthring.mm.contract.SleepDetailContract;
import com.smarthealthring.mm.presenter.HrDetailPresenter;
import com.smarthealthring.mm.presenter.SleepDetailPresenter;
import com.smarthealthring.mm.utils.ComToolBar;
import com.smarthealthring.mm.utils.RandomUtil;
import com.smarthealthring.mm.utils.SPUtils;
import com.smarthealthring.mm.widgets.SingleItemView;
import com.smarthealthring.mm.widgets.WrapContentListView;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.HashMap;
import java.util.List;

import butterknife.BindView;

/**
 * 步数二级页
 */
public class SleepDetailActivity extends BaseActivity<SleepDetailPresenter> implements SleepDetailContract.View {

    @BindView(R.id.ll_head)
    LinearLayout mllHeader;
    @BindView(R.id.lv_sleep)
    WrapContentListView mLvSleep;
    @BindView(R.id.iv_right)
    ImageView mIvRight;

    @Override
    protected void initComToolBar() {
        ImageView ivLeft = ComToolBar.setleftImg(mContext, R.drawable.back_white);
        RxView.clicks(ivLeft)
                .subscribe(o -> finish());
        ComToolBar.setTitle(mContext, "睡眠");
        ComToolBar.setRightImg(mContext,R.drawable.data_more_white);
    }

    @Override
    protected int getLayout() {
        return R.layout.act_sleep_detail;
    }

    @Override
    protected void initEventAndData(@Nullable Bundle savedInstanceState) {
        mIvRight.setVisibility(View.VISIBLE);

        mPresenter.sleepDetail(new HashMap<String, String>() {{
            put("trans_id", "2019");
            put("sign", "1111");
            put("username", SPUtils.getString(SPUtils.USERNAME, ""));
            put("nonce_str", RandomUtil.getRandomString(32));
            put("token", SPUtils.getString(SPUtils.TOKEN, "token=="));
        }});
    }

    @Override
    protected SleepDetailPresenter createPresenter() {
        return new SleepDetailPresenter();
    }

    @Override
    public void getSleepDetailSuccess(SleepDetailRes res) {
        if("1".equals(res.getHasdata())){
            List<SleepDetailRes.SleepmngBean> sleepmng = res.getSleepmng();
            mLvSleep.setAdapter(new CommonAdapter<SleepDetailRes.SleepmngBean>(this,R.layout.item_data_detail, sleepmng) {

                @Override
                protected void convert(ViewHolder viewHolder, SleepDetailRes.SleepmngBean item, int position) {
                    viewHolder.setText(R.id.tv_time, sleepmng.get(position).getWday());
//                    viewHolder.setText(R.id.tv_value, hrmng.get(position).);

                }

            });
        }else if("2".equals(res.getHasdata())) {
            Log.e("睡眠没有数据===","in...");
        }
    }

    @Override
    public void getSleepDetailFail() {

    }
}
